<template>
  <div class="user-box">

    <el-row>

      <el-breadcrumb separator="/">

        <el-breadcrumb-item>
          主页
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          系统设置
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          用户管理
        </el-breadcrumb-item>

      </el-breadcrumb>


    </el-row>
    <el-row>
      <el-col :span="24">

        <el-form label-width="60">
          <el-row>
            <el-col :span="8">
              <el-form-item label="用户名">
                <el-input></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="角色">
                <el-select v-model="data.query.roleId">
                    <el-option v-for="role in data.roles" :label="role.name" :value="role.roleId"></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item>
                <el-button type="primary"> 搜索</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-col>

    </el-row>


    <el-row>

      <el-button-group>
        <el-button type="success">添加</el-button>
        <el-button type="info">打印</el-button>
        <el-button type="warning">导入</el-button>
        <el-button type="danger">导出</el-button>
      </el-button-group>
      <el-table :data="data.list">
        <el-table-column type="selection"></el-table-column>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="username" label="用户名"></el-table-column>
        <el-table-column prop="roleName" label="角色"></el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="warning">修改</el-button>
            <el-button type="danger">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="prev, pager, next"  :total="10"></el-pagination>
    </el-row>


  </div>
</template>

<script lang="ts" setup>

import {reactive, onMounted} from "vue";
import request from "@/utils/request";

const data = reactive({
  list: new Array<Object>(),
  roles:new Array<Object>(),
  query:{
      roleId:-1
  }
})


function initTable() {
  request({
    url: '/user/list',
    method: 'get'
  }).then((res) => {
    data.list = res.data.data;
  })
}

function initRoles(){
   request({
      url:'/role/list',
       method:'get'
   }).then((res)=>{
       data.roles= res.data.data;
       data.roles.unshift({
          roleId:-1,
          name:'---所有角色'
       })
   })

}

onMounted(() => {
  initTable();
  initRoles();

})

</script>

<style scoped>

</style>